package org.dromara.comm_lhz.controller;

import lombok.AllArgsConstructor;
import org.dromara.comm_lhz.entity.AsTotalOrderEntity;
import org.dromara.comm_lhz.service.AsTotalOrderHService;
import org.dromara.comm_lhz.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 总订单控制器
 */
@RestController
@RequestMapping("/totalOrder")
@AllArgsConstructor
public class AsTotalOrderHController {

    @Autowired
    private AsTotalOrderHService asTotalOrderHService;

    /**
     * 获取订单列表
     * @return 订单列表
     */
    @GetMapping("/getTotalOrderList")
    public List<AsTotalOrderEntity> getTotalOrder() {
        return asTotalOrderHService.list();
    }

    /**
     * 获取订单详情
     * @param id 订单ID
     * @return 订单详情
     */
    @GetMapping("/getTotalOrderDetail")
    public AsTotalOrderEntity getTotalOrderDetail(Long id) {
        return asTotalOrderHService.getById(id);
    }

    /**
     * 添加订单
     * @param asTotalOrderEntity 订单实体
     */
    @PostMapping("/addTotalOrder")
    public void addTotalOrder(@RequestBody AsTotalOrderEntity asTotalOrderEntity) {
        asTotalOrderHService.addTotalOrder(asTotalOrderEntity);
    }

    /**
     * 修改订单
     * @param asTotalOrderEntity 订单实体
     */
    @PostMapping("/updateTotalOrder")
    public void updateTotalOrder(@RequestBody AsTotalOrderEntity asTotalOrderEntity) {
        if (asTotalOrderEntity.getStatus() == 2) {
             asTotalOrderHService.updateTotalOrderPay(asTotalOrderEntity);
        }else {
            asTotalOrderHService.updateTotalOrder(asTotalOrderEntity);
        }

    }

    /**
     * 删除订单
     * @param id 订单ID
     */
    @DeleteMapping("/deleteTotalOrder")
    public void deleteTotalOrder(Long id) {
        asTotalOrderHService.removeById(id);
    }

}
